#!/usr/bin/env python

import base64
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
import sys


def main():
	if len(sys.argv) >= 2:
		private_key = Ed25519PrivateKey.from_private_bytes(base64.b64decode(sys.argv[1]))
	else:
		private_key = Ed25519PrivateKey.generate()
	public_key = private_key.public_key()
	private_bytes = private_key.private_bytes(
		serialization.Encoding.Raw,
		serialization.PrivateFormat.Raw,
		serialization.NoEncryption()
	)
	public_bytes = public_key.public_bytes(
		serialization.Encoding.Raw,
		serialization.PublicFormat.Raw
	)
	print("ed25519 private key: %s" % base64.b64encode(private_bytes))
	print("ed25519 public key: %s" % base64.b64encode(public_bytes))


if __name__ == '__main__':
	main()
